<template>
  <div>
    <el-main>
      <topic
        :read="read"
        @upData="upData"
        :answer_id="answer_id"
        ref="pdfBox"
        id="pdf"
      ></topic>

      <div class="flex_btn">
        <div slot="footer" class="questionnaireBox" v-if="!read">
          <div>
            <el-button class="btn1" type="primary" plain @click="submit(1)"
            >保存草稿</el-button
          >
          <el-button class="btn2" type="primary" @click="submit(2)">马上提交</el-button>
          </div>
          <div class="contact">
            <a :href="`tel:${ophoneNumber}`">联系我们</a>
          </div>
         
        </div>
        <div v-else class="questionnaireBox">
          <div>
            <el-button class="btn1" type="primary" plain @click="loadPdf"
              >下载PDF</el-button
            >
            <el-popover placement="top" width="200" trigger="click">
              <div class="right">
                <div class="img">
                  <div id="qrcode" ref="qrcode"></div>
                </div>
              </div>
              <el-button slot="reference" class="btn2" type="primary" @click="qrcode1"
                >分享</el-button
              >
            </el-popover>
          </div>
        </div>
      </div>
    </el-main>
  </div>
</template>

<script>
import topic from "@/components/topic";
import QRCode from "qrcodejs2";
import { regionConfigList } from "@/api/configApi";

export default {
  data() {
    return {
      answer_id: "",
      read: false,
      ophoneNumber: ''
    };
  },
  components: { topic },
  mounted() {
    this.$route.query.read ? (this.read = true) : "";
    this.answer_id = this.$route.query.answer_id;
    regionConfigList().then(res => {
      this.ophoneNumber = res[1].value
    })
  },
  methods: {
    qrcode1(url, index) {
      this.$nextTick(() => {
        let qrcodeObj = this.$refs.qrcode;
        qrcodeObj.innerHTML = "";
        var qrcode = new QRCode(qrcodeObj, {
          text: window.location.href,
          width: 100,
          height: 100,
        });
      });
    },
    submit(type) {
      this.$refs.pdfBox.submit(type);
    },
    upData() {
      this.$router.go(-1);
    },
    loadPdf() {
      this.$refs.pdfBox.loadPdf();
    },
  },
};
</script>

<style scoped lang="less">
::v-deep .el-checkbox__input.is-disabled+span.el-checkbox__label {
  color: inherit;
}
::v-deep .el-radio__input.is-disabled+span.el-radio__label {
  color: inherit;

}
::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: #409EFF !important;
}
::v-deep .el-checkbox__input.is-checked+.el-checkbox__label {
  color: #409EFF !important;
}
::v-deep .el-radio__input.is-checked+.el-radio__label {
  color: #409EFF !important;
}
::v-deep .el-radio__input.is-checked .el-radio__inner {
  background: #409EFF !important;
}
::v-deep .el-input.is-disabled .el-input__inner {
  color: inherit;
}
::v-deep .el-form-item {
  margin-bottom: 8px;
}
::v-deep .el-checkbox__label {
  font-size: 16px;
}
::v-deep .el-checkbox {
  margin-bottom: 8px;
}
::v-deep  .el-form--label-top .el-form-item__label {
  padding: 0 12px 0 0;
  font-size: 16px;
}
::v-deep .el-radio__label {
  font-size: 16px;
}
::v-deep .el-radio {
  margin-bottom: 8px;
}
.contact {
  display: flex;
  align-items: center;
  background-color: #409eff;
  color: #fff;
  border-radius: 4px;
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
}
.btn2 {
  margin-left: 20px;
}
.el-main {
  // margin: 20px 15px;
}
.right {
  // width: 100%;
  // height: 200px;
  // margin-left:20
  .img {
    background-color: #fff;
    display: flex;
    justify-content: center;
  }
}
.operate {
  display: flex;
  justify-content: flex-end;
}
.flex_btn {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  background: #fff;
  display: flex;
  justify-content: center;
  z-index: 9;
  padding: 20px;
  .questionnaireBox {
    width: 720px;
    display: flex;
    justify-content: space-between;
  }
}
@media (max-width: 768px) {
  .flex_btn {
    .questionnaireBox {
      width: 100%;
    }
  }
}

@media (max-width: 1280px) {
}

@media (max-width: 1360px) {
}
</style>
